package com.topgay.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.topgay.domain.AnswerForInsert;
import com.topgay.domain.AnswerRaw;
import com.topgay.domain.MatchInfo;

@Repository
public class DatingDAOImple implements DatingDAO {

	@Autowired
	private SqlSessionTemplate session;

	@Override
	public int selectOneAnswer(String id){
		return session.selectOne("dating.selectOneAnswer", id);
	}
	
	@Override
	public int insertAnswerRaw(AnswerRaw answer, String id, String nickname) {

		List<Integer> list = answer.getAnswerRawList();
		int check = 0;
		for (int i = 0; i < 23; i++) {
			check = session.insert("dating.insertAnswerRaw", new AnswerForInsert(id, nickname, i+1, list.get(i)));
		}
		return check;

	}
	
	@Override
	public ArrayList<MatchInfo> selectAllAnswer(){
		return (ArrayList) session.selectList("dating.selectAllAnswer");
	}
	
	@Override
	public ArrayList<String> selectTimeLineName(String id){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		return (ArrayList) session.selectList("dating.selectTimeLineName", map);
	}
	
	@Override
	public MatchInfo selectTimeLineInfo(String id){
		return  session.selectOne("dating.selectTimeLineInfo", id);
	}

}
